package edu.njust.cma.mapper;

import edu.njust.cma.pojo.SubtaskAdditionalRequirement;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SubtaskAdditionalRequirementMapper {
    @Select("select * from subtasks_additional_requirements where task_id=#{taskId}")
    List<SubtaskAdditionalRequirement> getSubtaskAdditionalRequirement(Integer taskId);

    @Insert("insert into subtasks_additional_requirements(task_id,requirement_name,user_id,requirement_content) " +
            "values(#{taskId},#{requirementName},#{userId},#{requirementContent})")
    void insert(SubtaskAdditionalRequirement subtaskAdditionalRequirement);

    @Select("select * from subtasks_additional_requirements where user_id=#{userId}")
    List<SubtaskAdditionalRequirement> getSubtaskAdditionalRequirementByUserId(Integer userId);

    @Update("update subtasks_additional_requirements set id=#{id},status=#{status} where id=#{id}")
    void updateStatusById(Integer id, int status);

    @Select("select status from subtasks_additional_requirements where task_id=#{taskId}")
    List<Integer> getStatusByTaskId(Integer taskId);

    @Select("select status from subtasks_additional_requirements where id=#{id}")
    Integer getStatusById(Integer id);

    @Update("update subtasks_additional_requirements set attachment_pdf_url=#{attachmentPdfUrl} where id=#{id}")
    void updateUrlById(int id, String attachmentPdfUrl);

    @Update("update subtasks_additional_requirements set submission_time=#{nowTime} where id=#{id}")
    void updateTimeById(int id, String nowTime);

    @Select("select * from subtasks_additional_requirements where id=#{id}")
    SubtaskAdditionalRequirement getSubtaskAdditionalRequirementById(int id);

}
